package com.loan.controller.app.apply;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.util.ObjectUtil;
import com.loan.common.annotation.Log;
import com.loan.common.core.controller.BaseController;
import com.loan.common.core.domain.PageQuery;
import com.loan.common.core.domain.Result;
import com.loan.common.core.page.TableDataInfo;
import com.loan.common.enums.BusinessType;
import com.loan.system.domain.ApplyEntity;
import com.loan.system.domain.ApplyProductEntity;
import com.loan.system.domain.CompanyEntity;
import com.loan.system.service.ApplyProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author shiguang
 * @date 2022年09月20日 23:48
 */
@Validated
@Api(value = "产品管理", tags = {"产品管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/app/apply/product")
public class ApplyProductController extends BaseController {

    private final ApplyProductService applyProductService;

    /**
     * 获取产品列表
     */
    @ApiOperation("获取产品列表")
//    //@SaCheckPermissio("app:product:list")
    @GetMapping("/page")
    public TableDataInfo<ApplyProductEntity> list(ApplyProductEntity entity, PageQuery pageQuery) {
        return applyProductService.selectPageList(entity, pageQuery);
    }

    /**
     * 获取产品列表
     */
    @ApiOperation("获取产品列表")
//    //@SaCheckPermissio("app:product:list")
    @GetMapping("/list")
    public Result<List<ApplyProductEntity>> list() {
        return Result.ok(applyProductService.selectList());
    }

    /**
     * 根据id查询详情
     */
    @ApiOperation("根据id查询详情")
    //@SaCheckPermissio("app:product:query")
    @GetMapping(value = {"/{id}"})
    public Result<ApplyProductEntity> getInfo(@ApiParam("ID") @PathVariable Long id) {
        return Result.ok(applyProductService.selectApplyProductById(id));
    }

    /**
     * 新增产品
     */
    @ApiOperation("新增产品")
    //@SaCheckPermissio("app:product:add")
    @Log(title = "新增产品", businessType = BusinessType.INSERT)
    @PostMapping
    public Result<Void> add(@Validated @RequestBody ApplyProductEntity entity) {
        return toAjax(applyProductService.addApplyProduct(entity));
    }

    /**
     * 修改产品
     */
    @ApiOperation("修改产品")
    //@SaCheckPermissio("app:product:update")
    @Log(title = "修改产品", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result<Void> update(@Validated @RequestBody ApplyProductEntity entity) {
        return toAjax(applyProductService.updateApplyProduct(entity));
    }

    /**
     * 删除产品
     */
    @ApiOperation("删除产品")
//    @SaCheckPermissio("app:product:remove")
    @Log(title = "删除产品", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public Result<Void> remove(@ApiParam("ID") @PathVariable("id") Long id) {
        return toAjax(applyProductService.deleteApplyProductById(id));
    }

    /**
     * 产品状态修改
     */
    @ApiOperation("产品状态修改")
    //@SaCheckPermissio("app:product:update")
    @Log(title = "产品状态修改", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public Result<Void> changeStatus(@RequestBody ApplyProductEntity entity) {
        return toAjax(applyProductService.updateStatus(entity));
    }


}
